home *** CD-ROM | disk | FTP | other *** search
/ United Public Domain Gold 2 / United Public Domain Gold 2.iso / utilities / pu173.dms / pu173.adf / Source / ToolTypeWatch.c.pp / ToolTypeWatch.c
C/C++ Source or Header  |  1992-03-20  |  13KB  |  337 lines

  1. /*----------------------------------------------------------------------------
  2.    File   :    ToolTypeWatch.c
  3.    Projekt:    ToolTypeWatch
  4.    Inhalt :    LibCount1 - vor FindToolType geschaltet, dokumentiert Aufrufe
  5.                LibCount2 - vor MatchToolValue geschaltet,dokumentiert Aufrufe
  6.                CheckTask - eigenen Port überprüfen und ev. CTRL-C schicken
  7.                _main     - Haupt-PRG
  8.  
  9.    Version:    0.7
  10.    Datum  :    05. Januar 1992
  11.  
  12.    Autor  :    Uwe Röhm
  13.    Adresse:    Auber Str. 25,  W-6209 Hohenstein 4
  14.     (Semester) Wörthstr. 18    W-8390 Passau
  15.    Bemerkung:
  16. ----------------------------------------------------------------------------*/
  17. #include <exec/types.h>
  18. #include <exec/exec.h>
  19. #include <exec/io.h>
  20. #include <libraries/dosextens.h>
  21. #include <intuition/intuition.h>
  22.  
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <stdio.h>
  26. #include <proto/exec.h>
  27. #include <proto/dos.h>
  28. #include <proto/intuition.h>
  29.  
  30. #define HAILTEXT "\nToolTypeWatch V%ld.%ld   © 1991 by Uwe Röhm\nStart me again to adjust old icon.library vectors.\n\n"
  31. #define ERROR1 "ToolTypeWatch - Removed...\n"
  32. #define ERROR2 "ERROR while oppening Intuition.library V37!\n"
  33. #define ERROR3 "ERROR while oppening Window!\n"
  34. #define ERROR4 "ERROR while oppening console.device!\n"
  35. #define ERROR5 "ERROR: Couldn´t install new FindToolType() function!\n"
  36. #define ERROR6 "ERROR: Couldn´t install new MatchToolValue() function!\n"
  37. #define DEF_PORTNAME "ToolTypeWatch.port"
  38.  
  39.  
  40. /*  ---------------------   eigene Strukturen   -------------------------  */
  41. struct MyMessage {
  42.    struct Message m;
  43.    char text;
  44.    };
  45.  
  46. /*  ---------------------   Daten für cback.o   -------------------------  */
  47. long  _stack = 4000;
  48. char *_procname = "ToolTypeWatch";
  49. long  _priority = 0;
  50. long  _BackGroundIO = 1;
  51. extern BPTR _Backstdout;
  52.  
  53. /*  ---------------------   globale Variablen   -------------------------  */
  54. UBYTE* (* __regargs oldfunk) (UBYTE **toolTypeArray, UBYTE *typeName);
  55. BOOL   (* __regargs oldoldfunk) ( UBYTE *typeString, UBYTE *value);
  56. struct IntuitionBase *IntuitionBase;
  57. struct Library *IconBase;
  58. struct MsgPort *myport;
  59. extern long version, revision;
  60. /*  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
  61.    Funktion  :  LibCount1
  62.    Parameter :  UBYTE  **toolTypeArray
  63.                 UBYTE  *typeName
  64.    Rückgabe  :  UBYTE *(entweder NULL, oder value-String)
  65.  
  66.    Aufruf von:  überall und niergends
  67.    UnterFunks:  ---
  68.    Autor     :  Uwe Röhm
  69.    Datum     :  04. November 1991
  70.    Bemerkung:
  71.    Schickt zuerst die Übergabeparameter zu FindToolType und den Namen der
  72.    aktuellen Task an meinen HauptTask zur Ausgabe auf meinem Con-Window und
  73.    ruft dann die normale FindToolType-Funktion auf.
  74.    Den Umweg mit PutMsg mache ich, weil es sonst zu Abstürzen kam, als ich
  75.    von hier aus direkt mit DoIO arbeitete.
  76.    ACHTUNG: Ich erwarte meine Message nicht zurück (kein ReplyMsg),
  77.             dafür muß sie aber mit FreeMem wieder freigegeben werden (s.u.).
  78.    ACHTUNG: Die Argumente kommen in A1 und D0 (nicht A1/A2) an!!! Deshalb
  79.             gebe ich sie explizit per __asm und register an.
  80.    ACHTUNG: KEINE DOS-Aufrufe hier verwenden, da diese Routine ev. von
  81.             einfachen Tasks aufgerufen werden kann...
  82. --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  */
  83. UBYTE* __saveds __regargs LibCount1(UBYTE **toolTypeArray, UBYTE *typeName)
  84. {
  85.    UBYTE *retcode = NULL;
  86.    struct MyMessage *msg;
  87.    static char str[200];
  88.  
  89.    Forbid();   /* wegen SysBase-Zugriff... */
  90.    sprintf (str, "%s:  Find ToolType '%s'   (erstes '%s')\n",
  91.             SysBase->ThisTask->tc_Node.ln_Name, typeName, *toolTypeArray);
  92.    Permit();
  93.  
  94.    // Message an HauptTask für die Ausgabe auf meiner Console
  95.    if (msg = AllocMem (sizeof(struct Message) + strlen(str) + 1, MEMF_CLEAR))
  96.    {
  97.       strcpy (&msg->text, str);
  98.       msg->m.mn_Length = sizeof(struct Message) + strlen(str) + 1;
  99.       PutMsg (myport, (struct Message *) msg);
  100.    } // if AllocMem
  101.  
  102.    // Ur-FindToolType aufrufen
  103.    retcode = oldfunk(toolTypeArray, typeName);
  104.    return retcode;
  105. }
  106.  
  107. /*  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
  108.    Funktion  :  LibCount2
  109.    Parameter :  UBYTE        *typeString (mehrere (?) Values eines ToolTypes)
  110.                 UBYTE        *value      (ist dieser Wert darin enthalten)
  111.    Rückgabe  :  BOOL (Ja oder nein...)
  112.  
  113.    Aufruf von:  überall und niergends
  114.    UnterFunks:  ---
  115.    Autor     :  Uwe Röhm
  116.    Datum     :  04. November 1991
  117.    Bemerkung:
  118.    Wie LibCount1, nur für die MatchToolValue-Funktion.
  119.    ACHTUNG: KEINE DOS-Aufrufe hier verwenden, da diese Routine ev. von
  120.             einfachen Tasks aufgerufen werden kann...
  121. --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  */
  122. BOOL __saveds __regargs LibCount2(UBYTE *typeString, UBYTE *value)
  123. {
  124.    BOOL retcode = FALSE;
  125.    struct MyMessage *msg;
  126.    static char str[200];
  127.  
  128.    Forbid();   /* wegen SysBase-Zugriff... */
  129.    sprintf (str, "%s:  Wert von '%s' in %s'?? (MatchToolValue)\n",
  130.             SysBase->ThisTask->tc_Node.ln_Name, value, typeString);
  131.    Permit();
  132.  
  133.    // Ausgabe auf meiner Console
  134.    if (msg = AllocMem (sizeof(struct Message) + strlen(str) + 1, MEMF_CLEAR))
  135.    {
  136.       strcpy (&msg->text, str);
  137.       msg->m.mn_Length = sizeof(struct Message) + strlen(str) + 1;
  138.       PutMsg (myport, (struct Message *) msg);
  139.    } // if AllocMem
  140.  
  141.    // Ur-MatchToolValue aufrufen
  142.    retcode = oldoldfunk(typeString, value);
  143.    return retcode;
  144. }
  145.  
  146. /*  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
  147.    Funktion  :  CheckTask
  148.    Parameter :  ---
  149.    Rückgabe  :  struct MsgPort * (erzeugter MsgPort)
  150.  
  151.    Aufruf von:  main (s.u.)
  152.    UnterFunks:  ---
  153.    Autor     :  Uwe Röhm
  154.    Datum     :  02. November 1991
  155.    Bemerkung:
  156. --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  */
  157. struct MsgPort *CheckTask (void)
  158. {
  159. struct MsgPort *tmp = NULL;
  160.  
  161.    if ((tmp = (struct MsgPort *) FindPort (DEF_PORTNAME)))
  162.    {
  163.       Signal (tmp->mp_SigTask, SIGBREAKF_CTRL_C);
  164.       return (NULL);
  165.    }
  166.    else
  167.    {   tmp = CreatePort (DEF_PORTNAME, 0);  }
  168.  
  169.    return tmp;
  170. }
  171.  
  172.  
  173. /*  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
  174.    Funktion  :  _main
  175.    Parameter :  char *cmd (die einzelnen Argumente)
  176.    Rückgabe  :  ---
  177.  
  178.    Aufruf von:  CLI / WB
  179.    UnterFunks:
  180.    Autor     :  Uwe Röhm
  181.    Datum     :  04. November 1991
  182.    Bemerkung:
  183.    Ein Ausgabewindow wird geöffnet und dann per SetFunction die FindToolType()
  184.    und die MatchToolValkue() Funktionen gepatched. Danach warte ich darauf,
  185.    daß ein erneuter Aufruf dieses Programmes an meinen SystemPort ein Break-
  186.    Signal sendet. Ausgaben werden nur von hier aus getätigt. Ich bekomme dazu
  187.    von meinen eingepatchten Funktionen Messages mit den entspr. Texten.
  188. --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  */
  189. void main (int argc, char *argv[])
  190. {
  191.    BOOL retcode;
  192.    ULONG sigbits;
  193.    char string[150];
  194.    struct Message *msg;
  195.    struct Window *mywin;
  196.    struct IOStdReq ioreq;
  197.    struct MyMessage *mymsg;
  198.    WORD zoomkoords[4] = {12,12,70,12};
  199.  
  200.    sprintf (string, HAILTEXT, version, revision);
  201.    Write (_Backstdout, string, strlen(string));
  202.  
  203.    myport = CheckTask ();
  204.    retcode = (myport == NULL) ? FALSE : TRUE;
  205.    if (retcode)
  206.    {
  207.       IntuitionBase = OpenLibrary ("intuition.library", 37L);
  208.       retcode = (IntuitionBase == NULL) ? FALSE : TRUE;
  209.       if (retcode)
  210.       {
  211.         IconBase = OpenLibrary ("icon.library", 37L);
  212.         retcode = (IconBase == NULL) ? FALSE : TRUE;
  213.         if (retcode)
  214.         {
  215.          mywin = OpenWindowTags (NULL, WA_Height,200,
  216.                                        WA_Width, 600,
  217.                                        WA_MinWidth, 70,
  218.                                        WA_MinHeight, 40,
  219.                                        WA_MaxWidth, -1,
  220.                                        WA_MaxHeight, -1,
  221.                                        WA_Title, "ToolTypeWatch - Output",
  222.                                        WA_DetailPen, 1,
  223.                                        WA_CloseGadget, TRUE,
  224.                                        WA_DragBar, TRUE,
  225.                                        WA_DepthGadget, TRUE,
  226.                                        WA_Zoom, &zoomkoords,
  227.                                        WA_SizeGadget, TRUE,
  228.                                        WA_SimpleRefresh, TRUE,
  229.                                        WA_IDCMP, IDCMP_CLOSEWINDOW,
  230.                                        TAG_DONE);
  231.          retcode = (mywin == NULL) ? FALSE : TRUE;
  232.          if (retcode)
  233.          {
  234.             // Console UnitNr. 3 + SimpleRefresh (s.o.) :
  235.             //  - autom. Updaten des Textes bei Sizing des Windows
  236.             //  - mögliches Ausschneiden von Text ins ClipBoard
  237.             ioreq.io_Data = (APTR) mywin;
  238.             retcode = (OpenDevice("console.device", 3, &ioreq, NULL) == 0) ? TRUE : FALSE;
  239.             if (retcode)
  240.             {
  241.                // ACHTUNG: Negativer Offset und Hexadezimal!!!
  242.                oldfunk = SetFunction ((struct Library *)IconBase, -0x60,(APTR)LibCount1);
  243.                retcode = (oldfunk == NULL) ? FALSE : TRUE;
  244.                if (retcode)
  245.                {
  246.                   // ACHTUNG: Negativer Offset und Hexadezimal!!!
  247.                   oldoldfunk = SetFunction ((struct Library *)IconBase, -0x66,(APTR)LibCount2);
  248.                   retcode = (oldoldfunk == NULL) ? FALSE : TRUE;
  249.                   if (retcode)
  250.                   {
  251.                      Close (_Backstdout);
  252.                      _Backstdout = NULL;
  253.  
  254.                      do
  255.                      {
  256.                         sigbits = Wait (SIGBREAKF_CTRL_C | (1 << mywin->UserPort->mp_SigBit) | (1 << myport->mp_SigBit));
  257.                         //
  258.                         // Angefragte Ausgaben machen
  259.                         //
  260.                         if (sigbits & (1 << myport->mp_SigBit))
  261.                         {
  262.                            while (mymsg = (struct MyMessage *) GetMsg (myport))
  263.                            {
  264.                               ioreq.io_Command = CMD_WRITE;
  265.                               ioreq.io_Data    = (APTR) &mymsg->text;
  266.                               ioreq.io_Length  = -1;
  267.                               DoIO(&ioreq);
  268.                               FreeMem (mymsg, mymsg->m.mn_Length);
  269.                            } /* if GetMsg */
  270.                         } /* if myport */
  271.                         //
  272.                         // Close Gadget - Fenster schliessen
  273.                         //
  274.                         if (sigbits & (1 << mywin->UserPort->mp_SigBit))
  275.                         {
  276.                            while (msg = GetMsg(mywin->UserPort))
  277.                               ReplyMsg(msg);
  278.                            sigbits |= SIGBREAKF_CTRL_C;
  279.                         } /* if UserPort */
  280.                      }
  281.                      while (!(sigbits & SIGBREAKF_CTRL_C));
  282.  
  283.                      SetFunction ((struct Library *)IconBase, -0x66, (APTR) oldoldfunk);
  284.                   }
  285.                   else
  286.                   {  Write (_Backstdout, ERROR6, sizeof (ERROR6));    }
  287.  
  288.                   SetFunction ((struct Library *)IconBase, -0x60, (APTR) oldfunk);
  289.                } // if SetFunction
  290.                else
  291.                {  Write (_Backstdout, ERROR5, sizeof (ERROR5));      }
  292.  
  293.                CloseDevice(&ioreq);
  294.             } // if OpenDevice
  295.             else
  296.             {  Write (_Backstdout, ERROR4, sizeof (ERROR4));      }
  297.  
  298.             CloseWindow (mywin);
  299.          } // if OpenWindow
  300.          else
  301.           {  Write (_Backstdout, ERROR3, sizeof (ERROR3));   }
  302.  
  303.          CloseLibrary (IconBase);
  304.         } // if IconBase
  305.  
  306.         CloseLibrary (IntuitionBase);
  307.       } // if IntuitionBase
  308.       else
  309.       {  Write (_Backstdout, ERROR2, sizeof(ERROR2));    }
  310.  
  311.    } // if CheckTask
  312.    else
  313.    {  Write (_Backstdout, ERROR1, sizeof (ERROR1));     }
  314.  
  315.  
  316.    //
  317.    //    meinen Port sauber schliessen
  318.    //
  319.    if (myport)
  320.    {
  321.       while (msg = GetMsg (myport))
  322.       {
  323.          if (msg->mn_Length == sizeof(struct Message))
  324.             ReplyMsg (msg); // Wer immer es war, er kriegt sie wieder
  325.          else
  326.             FreeMem (msg, msg->mn_Length); // Nachzügler meiner AusgabeMessages
  327.       }
  328.       DeletePort (myport);
  329.       myport = NULL;
  330.    }
  331.  
  332.    if (_Backstdout != NULL)
  333.       Close (_Backstdout);
  334.    exit ((retcode == TRUE) ? 0 : 10);
  335.  
  336. }
  337.